#include "stereovision.h"
#include "object.h"
#include <QDebug>
#include <QApplication>
#include <QDesktopWidget>

StereoVision::StereoVision( QObject *parent ) :
    QObject( parent )
{
    _camera = new Camera;
    _camera->eyesep = 2.f;
    _camera->aperture = 45;

    _camera->vp.x = 0;
    _camera->vp.y = 0;
    _camera->vp.z = 30;

    _camera->vd.x = 0;
    _camera->vd.y = 0;
    _camera->vd.z = -1;

    _camera->vu.x = 0;
    _camera->vu.y = 1;
    _camera->vu.z = 0;

    _camera->screenwidth = 1024;
    _camera->screenheight = 768;

    _camera->focallength = 1;

    _camera->fnear = 10.f;
    _camera->ffar = 100.f;

    _obj_l = new MyGLObject( true, _camera );
    _obj_r = new MyGLObject( false, _camera );

    QRect screenres0 = QApplication::desktop()->screenGeometry( 0 );
    QRect screenres1 = QApplication::desktop()->screenGeometry( 1 );

    _obj_l->move(QPoint(screenres0.x(), screenres0.y()));
    _obj_r->move(QPoint(screenres1.x(), screenres1.y()));

    _obj_l->show();
    _obj_r->show();

    // bind signals/slots between the two objects so they will share
    //   keyboard press events
    connect( _obj_l, SIGNAL( cameraChanged() ),
             _obj_r, SLOT( updateGL() ) );
    connect( _obj_r, SIGNAL( cameraChanged() ),
             _obj_l, SLOT( updateGL() ) );

    // close the other window if one is closed
    connect( _obj_l, SIGNAL( closed()),
             _obj_r, SLOT( close ()));
    connect( _obj_r, SIGNAL( closed()),
             _obj_l, SLOT( close ()));
}

StereoVision::~StereoVision()
{
    _obj_l->close();
    _obj_r->close();
    delete _obj_l;
    delete _obj_r;
    delete _camera;
    qDebug() << "Exit stereo vision.";
}
